package com.yoshino.prototype.deepclone;

/**
 * @author yoshino
 **/
public class Client {
    public static void main(String[] args) {
        DeepProtoType p = new DeepProtoType();
        p.setName("yoshino");
        p.deepCloneableTarget = new DeepCloneableTarget("hh", "hh.class");
        // 方式1
        try {
            DeepProtoType DeepProtoType2 = (DeepProtoType)p.clone();
            DeepProtoType DeepProtoType3 = (DeepProtoType)p.clone();
            DeepProtoType DeepProtoType4 = (DeepProtoType)p.clone();
            System.out.println(DeepProtoType2);
            System.out.println(DeepProtoType3);
            System.out.println(DeepProtoType4);
            // false
            System.out.println(p == DeepProtoType2);
            // false
            System.out.println(DeepProtoType2 == DeepProtoType3);
            // false
            System.out.println(p.getDeepCloneableTarget() == DeepProtoType2.getDeepCloneableTarget());
            // false
            System.out.println(p.getDeepCloneableTarget().hashCode());
            System.out.println(DeepProtoType2.getDeepCloneableTarget().hashCode());
            System.out.println(p.hashCode());
            System.out.println(DeepProtoType2.hashCode());
            // false
            System.out.println(DeepProtoType2.getDeepCloneableTarget() == DeepProtoType3.getDeepCloneableTarget());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

        // 方式二
        System.out.println("=====================");
        try {
            DeepProtoType DeepProtoType2 = (DeepProtoType)p.deepClone();
            DeepProtoType DeepProtoType3 = (DeepProtoType)p.deepClone();
            System.out.println(DeepProtoType2);
            System.out.println(DeepProtoType3);
            // false
            System.out.println(p == DeepProtoType2);
            // false
            System.out.println(DeepProtoType2 == DeepProtoType3);
            // false
            System.out.println(p.getDeepCloneableTarget() == DeepProtoType2.getDeepCloneableTarget());
            // false
            System.out.println(p.getDeepCloneableTarget().hashCode());
            System.out.println(DeepProtoType2.getDeepCloneableTarget().hashCode());
            System.out.println(p.hashCode());
            System.out.println(DeepProtoType2.hashCode());
            // false
            System.out.println(DeepProtoType2.getDeepCloneableTarget() == DeepProtoType3.getDeepCloneableTarget());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
